# -*- coding:utf-8 -*-
# AudibleAlgos
# Vincent Foley-Bourgon - vfoley <at> gmail <dot> com

import random
import itertools

from pyo import midiToHz

def AnyValue():
    return random.randint(200, 500)

def GenerateMajorScale(first_note, limit):
    incr = itertools.cycle([2, 2, 1, 2, 2, 2, 1])
    curr = first_note
    while curr <= limit:
        yield curr
        curr += next(incr)


scales = {
    "C": midiToHz(list(GenerateMajorScale(48, 84))),
    "D": midiToHz(list(GenerateMajorScale(50, 86))),
    "E": midiToHz(list(GenerateMajorScale(52, 88))),
    "F": midiToHz(list(GenerateMajorScale(53, 89))),
    "G": midiToHz(list(GenerateMajorScale(43, 79))),
    "A": midiToHz(list(GenerateMajorScale(45, 81))),
    "B": midiToHz(list(GenerateMajorScale(47, 83))),
}

def MajorScale(scale):
    notes = scales[scale]
    return random.choice(notes)

def AMinPenta():
    """Do, Re, Mi, Sol, La"""
    scale = midiToHz([48, 50, 52, 55, 57,
                      60, 62, 64, 67, 69,
                      72, 74, 76, 79, 81, 84])
    return random.choice(scale)
